package org.yuanqiframework.yuanqi.web.mq.handle;

import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.connection.CorrelationData;
import org.springframework.amqp.rabbit.core.RabbitTemplate;

@Slf4j
public class ConfirmCallback implements RabbitTemplate.ConfirmCallback {
    /**
     * 消息确认回调方法
     * 从发布者到交换机
     *
     * @param correlationData
     * @param ack
     * @param cause
     */
    @Override
    public void confirm(CorrelationData correlationData, boolean ack, String cause) {
        if (correlationData == null) {
            correlationData = new CorrelationData();
        }
        if (ack) {
            log.info("消息到达交换机 ID => {}", correlationData.getId());
        } else {
            log.error("消息投递失败 {} 原因 => {}", correlationData.getId(), cause);
        }
    }
}
